import { config } from '../../../config';
import { sequelize } from '../../db';
import { Model, DataTypes } from 'sequelize';
class Material extends Model { }

Material.init({
    name: DataTypes.STRING,
    UserId: DataTypes.INTEGER,
    MaterialTypeId: DataTypes.INTEGER,
    address: DataTypes.STRING,
    phone: DataTypes.STRING,
    img: DataTypes.STRING,
    fullUrl: {
        type: DataTypes.VIRTUAL,
        get() {
            return this.dataValues.img ? config.BASEURL + this.dataValues.img : ''
        },
        set(value) {
            throw new Error('不要尝试设置 `fullUrl` 的值!');
        }
    },
    state: {
        type: DataTypes.INTEGER,
        defaultValue: true
    }
}, {
    sequelize
});

export default Material